home *** CD-ROM | disk | FTP | other *** search
/ Teach Your Children: Road Construction Ahead / Teach Your Children: Road Construction Ahead.iso / pc / rca / road.dxr / 00004_UserName Parent.ls < prev    next >
Encoding:
Text File  |  1996-07-17  |  6.8 KB  |  233 lines

  1. property userName, firstChannel, locH, locV, letterHoffsets, firstLetterBmap, levelBmapChannel, cursor, levelLocH, levelLocV, savedGameList, nameString, maxChars, onOrOff, cursorCounter, maxWidth, cursorSpeed, maxCharWidth, oldUserGameNum
  2. global gLevelObject, gMenuObject, gHelpObject
  3.  
  4. on birth me
  5.   set firstChannel to 26
  6.   set locH to 147
  7.   set locV to 211
  8.   set levelBmapChannel to 25
  9.   set levelLocH to 450
  10.   set levelLocV to 60
  11.   set maxChars to 11
  12.   set maxCharWidth to 18
  13.   set userName to []
  14.   set letterHoffsets to [0]
  15.   set firstLetterBmap to the number of cast "a.lower"
  16.   set cursor to firstLetterBmap + 53
  17.   set savedGameList to []
  18.   set nameString to EMPTY
  19.   set oldUserGameNum to 0
  20.   set onOrOff to 0
  21.   set cursorCounter to 1
  22.   set cursorSpeed to 6
  23.   set maxWidth to 156
  24.   return me
  25. end
  26.  
  27. on update me
  28.   if count(userName) = 0 then
  29.     blinkQuestion(me)
  30.   end if
  31. end
  32.  
  33. on keyHandler me
  34.   set whichKey to the key
  35.   set ascii to charToNum(whichKey)
  36.   if (ascii >= 65) and (ascii <= 90) then
  37.     enterLetter(me, whichKey, ascii - 64)
  38.   else
  39.     if (ascii >= 97) and (ascii <= 122) then
  40.       enterLetter(me, whichKey, ascii - 96)
  41.     else
  42.       if ascii = 8 then
  43.         eraseLetter(me)
  44.       else
  45.         if ascii = 45 then
  46.           enterLetter(me, whichKey, 53)
  47.         end if
  48.       end if
  49.     end if
  50.   end if
  51. end
  52.  
  53. on charToBitmap me, keyString
  54.   set ascii to charToNum(keyString)
  55.   if (ascii >= 97) and (ascii <= 122) then
  56.     set castPos to ascii - 96
  57.   else
  58.     if (ascii >= 65) and (ascii <= 90) then
  59.       set castPos to ascii - 38
  60.     else
  61.       if ascii = 45 then
  62.         set castPos to 53
  63.       end if
  64.     end if
  65.   end if
  66.   return castPos
  67. end
  68.  
  69. on setDefaultUserName me
  70.   set nameList to ["Crusher", "Big-Shot", "Dozer", "Digger"]
  71.   set defaultName to getAt(nameList, random(count(nameList)))
  72.   repeat with x = 1 to the number of chars in defaultName
  73.     set letter to char x of defaultName
  74.     set letterNum to charToBitmap(me, letter)
  75.     set whichCast to firstLetterBmap + letterNum - 1
  76.     set letterWidth to getKernValue(whichCast)
  77.     set currentOffset to getLast(letterHoffsets)
  78.     add(userName, letterNum)
  79.     add(letterHoffsets, currentOffset + letterWidth)
  80.   end repeat
  81.   set the saveEnabled of gMenuObject to 0
  82. end
  83.  
  84. on enterLetter me, whichKey, letterNum
  85.   if ((getLast(letterHoffsets) + maxCharWidth) <= maxWidth) and (count(userName) < maxChars) then
  86.     set channel to firstChannel + count(userName)
  87.     if count(userName) = 0 then
  88.       if letterNum = 53 then
  89.         exit
  90.       end if
  91.       set letterNum to letterNum + 26
  92.     end if
  93.     set whichCast to firstLetterBmap + letterNum - 1
  94.     set letterWidth to getKernValue(whichCast)
  95.     set the castNum of sprite channel to whichCast
  96.     set currentOffset to getLast(letterHoffsets)
  97.     set the locH of sprite channel to locH + currentOffset
  98.     set the locV of sprite channel to locV
  99.     updateStage()
  100.     add(userName, letterNum)
  101.     add(letterHoffsets, currentOffset + letterWidth)
  102.     set nameString to nameString & whichKey
  103.   else
  104.     beep(1)
  105.   end if
  106. end
  107.  
  108. on eraseLetter me
  109.   if count(userName) > 0 then
  110.     deleteAt(userName, count(userName))
  111.     deleteAt(letterHoffsets, count(letterHoffsets))
  112.     set the locH of sprite (firstChannel + count(userName)) to 1000
  113.     updateStage()
  114.     set nameLength to length(nameString)
  115.     if nameLength > 1 then
  116.       set nameString to char 1 to nameLength - 1 of nameString
  117.     else
  118.       set nameString to EMPTY
  119.     end if
  120.   else
  121.     beep(1)
  122.   end if
  123. end
  124.  
  125. on blinkQuestion me
  126.   if cursorCounter > cursorSpeed then
  127.     if onOrOff = 0 then
  128.       set the locH of sprite firstChannel to locH
  129.       set the locV of sprite firstChannel to locV
  130.       set the castNum of sprite firstChannel to cursor
  131.       set onOrOff to 1
  132.     else
  133.       set the locH of sprite firstChannel to 1000
  134.       set onOrOff to 0
  135.     end if
  136.     set cursorCounter to 0
  137.   else
  138.     set cursorCounter to cursorCounter + 1
  139.   end if
  140. end
  141.  
  142. on fillName me
  143.   drawUserName(me, firstChannel, locH, locV)
  144. end
  145.  
  146. on drawUserName me, channelNum, Xloc, Yloc
  147.   repeat with x = 1 to count(userName)
  148.     set channel to firstChannel + x - 1
  149.     puppetSprite(channel, 1)
  150.     set the castNum of sprite channel to firstLetterBmap + getAt(userName, x) - 1
  151.     set the locH of sprite channel to Xloc + getAt(letterHoffsets, x)
  152.     set the locV of sprite channel to Yloc
  153.   end repeat
  154.   repeat with x = count(userName) + 1 to maxChars
  155.     set channel to firstChannel + x - 1
  156.     set the locH of sprite channel to 1000
  157.     puppetSprite(channel, 0)
  158.   end repeat
  159. end
  160.  
  161. on addPeriod me
  162.   set periodSprite to firstChannel + count(userName)
  163.   set the castNum of sprite periodSprite to firstLetterBmap + 54
  164.   set the locH of sprite periodSprite to the nameX of gMenuObject + getLast(letterHoffsets)
  165.   set the locV of sprite periodSprite to the nameY of gMenuObject
  166.   puppetSprite(periodSprite, 1)
  167. end
  168.  
  169. on drawUserLevel me
  170.   set the castNum of sprite levelBmapChannel to getAt(the bmapList of gLevelObject, the level of gLevelObject)
  171.   set the locH of sprite levelBmapChannel to levelLocH
  172.   set the locV of sprite levelBmapChannel to levelLocV
  173.   puppetSprite(levelBmapChannel, 1)
  174. end
  175.  
  176. on unpuppetUserData me
  177.   repeat with x = 1 to count(userName) + 1
  178.     set channel to firstChannel + x - 1
  179.     puppetSprite(channel, 0)
  180.   end repeat
  181.   puppetSprite(levelBmapChannel, 0)
  182. end
  183.  
  184. on puppetUserData me
  185.   repeat with x = 1 to count(userName)
  186.     set channel to firstChannel + x - 1
  187.     puppetSprite(channel, 1)
  188.   end repeat
  189.   puppetSprite(levelBmapChannel, 1)
  190. end
  191.  
  192. on puppetAllUserSprites me
  193.   repeat with x = 1 to 12
  194.     set channel to firstChannel + x - 1
  195.     puppetSprite(channel, 1)
  196.   end repeat
  197. end
  198.  
  199. on saveUserData me
  200.   set userDataString to string(the quitEnabled of gMenuObject) & ","
  201.   set userDataString to userDataString & string(the printEnabled of gMenuObject) & ","
  202.   set userDataString to userDataString & nameString & ","
  203.   repeat with x in userName
  204.     set userDataString to userDataString & string(x) & ","
  205.   end repeat
  206.   repeat with x = 2 to count(letterHoffsets)
  207.     set userDataString to userDataString & string(getAt(letterHoffsets, x)) & ","
  208.   end repeat
  209.   return userDataString
  210. end
  211.  
  212. on loadUserData me, index
  213.   set the quitEnabled of gMenuObject to value(item index of the dataString of gMenuObject)
  214.   set index to index + 1
  215.   set the printEnabled of gMenuObject to value(item index of the dataString of gMenuObject)
  216.   set index to index + 1
  217.   set nameString to item index of the dataString of gMenuObject
  218.   set letterQuantity to length(nameString)
  219.   set userName to []
  220.   set letterHoffsets to [0]
  221.   repeat with x = 1 to letterQuantity
  222.     add(userName, value(item index + x of the dataString of gMenuObject))
  223.   end repeat
  224.   repeat with x = 1 to letterQuantity
  225.     add(letterHoffsets, value(item index + letterQuantity + x of the dataString of gMenuObject))
  226.   end repeat
  227.   return index + (letterQuantity * 2) + 1
  228. end
  229.  
  230. on help me, buttonObject
  231.   birth(script "Help Parent", buttonObject, #LogIn)
  232. end
  233.